﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using Cash.Model;
using System.Globalization;

namespace CashConnect
{
    class CashTaxesGate : ITaxesGate
    {
        public List<Taxes> GetTaxes()
        {
            List<Taxes> listTaxes = new List<Taxes>();

            String sql =
                " SELECT fth.D_Date_Begin,fth.F_Taxes,fth.N_Value,ft.C_Name, ft.C_Const FROM dbo.FS_Tax_History fth" +
                " INNER JOIN dbo.FS_Taxes ft ON ft.LINK = fth.F_Taxes WHERE  F_Taxes = 4 ORDER BY N_Value";

            SqlCommand cmd = new SqlCommand(sql, WFSql.DB.SqlConnection, WFSql.DB.SqlTransaction);
            cmd.Transaction = WFSql.DB.SqlTransaction;

            using (SqlDataReader sdr = cmd.ExecuteReader())
            {
                while (sdr.Read())
                {
                    listTaxes.Add(
                        new Taxes(
                            Convert.ToDateTime(sdr["D_Date_Begin"], CultureInfo.InvariantCulture),
                            Convert.ToInt32(sdr["F_Taxes"], CultureInfo.InvariantCulture),
                            Convert.ToDouble(sdr["N_Value"], CultureInfo.InvariantCulture),
                            sdr["C_Name"].ToString(),
                            sdr["C_Const"].ToString()
                            )
                        );
                }
            }
            return listTaxes;
        }

    }
}
